package online.shenjian.mq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = "spring.rabbitmq.enable", matchIfMissing = true)
public class RpcClient {

    private RabbitTemplate rabbitTemplate;

    public RpcClient(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void send() {
        System.out.println(" [客户端] 发送请求10");
        Integer response = (Integer) rabbitTemplate.convertSendAndReceive("rpc", "rpc", 10);
        System.out.println(" [客户端] 收到响应 " + response + "");
    }
}
